<template>
    <div class="drawerForm-wrapper">
      <el-drawer
        title="补录过磅单"
        direction="rtl"
        :close-on-click-modal="false"
        :visible.sync="detailVisible">
        <el-form
          :inline="true"
          label-width="94px"
          ref="editForm"
          :model="editForm"
          style="position: relative"
        >
            <el-row>
                <el-radio-group v-model="radioVal" @change="changeRadio">
                    <el-radio :label="1">有派车单</el-radio>
                    <el-radio :label="2">无派车单</el-radio>
                </el-radio-group>
            </el-row>
            <div v-if="radioVal === 1">
                <el-row>
                    <el-form-item label="派车单号:">
                        <el-input v-model="transportMsg.transCode" @focus="getTransportClient"></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="发运计划:">
                        <el-input v-model="transportMsg.planCode" @focus="getTransPlanClient" :disabled="true"></el-input>
                    </el-form-item>
                    <el-form-item label="客户名称:">
                        <el-input v-model="transportMsg.companyName" :disabled="true"></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="产品名称:">
                        <el-input v-model="transportMsg.productName" :disabled="true"></el-input>
                    </el-form-item>
                    <el-form-item label="业务流程:">
                        <div class="adjust-content">{{$dictUtils.getDictLabel('processType', transportMsg.processType, '')}}</div>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="车牌号:">
                        <el-input v-model="transportMsg.truckNumber" @focus="getTruckClient" :disabled="true"></el-input>
                    </el-form-item>
                    <el-form-item label="车轴类型:">
                        <el-input v-model="transportMsg.axleName" :disabled="true"></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="司机姓名:">
                        <el-input v-model="transportMsg.driverName" @focus="getDriverClient" :disabled="true"></el-input>
                    </el-form-item>
                    <el-form-item label="司机电话:">
                        <el-input v-model="transportMsg.driverPhone" :disabled="true"></el-input>
                    </el-form-item>
                </el-row>
            </div>
            <div v-if="radioVal === 2">
                <el-row>
                    <el-form-item label="发运计划:">
                        <el-input v-model="transportMsg.planCode"  @focus="getTransPlanClient"></el-input>
                    </el-form-item>
                    <el-form-item label="客户名称:">
                        <el-input v-model="transportMsg.companyName"></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="产品名称:">
                        <el-input v-model="transportMsg.productName"></el-input>
                    </el-form-item>
                    <el-form-item label="业务流程:">
                        <div class="adjust-content">{{$dictUtils.getDictLabel('processType', transportMsg.processType, '')}}</div>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="车牌号:">
                        <el-input v-model="transportMsg.truckNumber" @focus="getTruckClient"></el-input>
                    </el-form-item>
                    <el-form-item label="车轴类型:">
                        <el-input v-model="transportMsg.axleName"></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="司机姓名:">
                        <el-input v-model="transportMsg.driverName" @focus="getDriverClient"></el-input>
                    </el-form-item>
                    <el-form-item label="司机电话:">
                        <el-input v-model="transportMsg.driverPhone"></el-input>
                    </el-form-item>
                </el-row>
            </div>
            <el-row>
            <div class="title">
                <el-form-item label="重量信息:">
                    <span>（单位:吨）</span>
                </el-form-item>
            </div>
            </el-row>

            <el-row>
                <el-form-item label="毛重:">
                    <el-input v-model="weightMsg.measuredGross" v-thousands.measuredGross="weightMsg"></el-input>
                </el-form-item>
                <el-form-item label="毛重时间:">
                    <el-date-picker
                        v-model="weightMsg.grossTime"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
            </el-row>
            <el-row>
                <el-form-item label="皮重:">
                    <el-input v-model="weightMsg.measuredTare"  v-thousands.measuredTare="weightMsg">></el-input>
                </el-form-item>
                <el-form-item label="皮重时间:">
                    <el-date-picker
                        v-model="weightMsg.tareTime"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
            </el-row>
            <el-row>
                <el-form-item label="净重:">
                    <el-input v-model="weightMsg.netWeightMeasured" v-thousands.netWeightMeasured="weightMsg"></el-input>
                </el-form-item>
                <el-form-item label="暗扣:">
                    <el-input v-model="weightMsg.deductWeight" v-thousands.deductWeight="weightMsg"></el-input>
                </el-form-item>
            </el-row>
            <el-row>
                <el-form-item label="扣杂:">
                    <el-input v-model="weightMsg.deductWeightImpurity"  v-thousands.deductWeightImpurity="weightMsg"></el-input>
                </el-form-item>
                <el-form-item label="扣水:">
                    <el-input v-model="weightMsg.deductWeightWater"  v-thousands.deductWeightWater="weightMsg"></el-input>
                </el-form-item>
            </el-row>
            <el-row>
                <el-form-item label="超载(调整):">
                    <el-input v-model="weightMsg.overloadAdjustWeight"  v-thousands.overloadAdjustWeight="weightMsg"></el-input>
                </el-form-item>
                <el-form-item label="毛重(调整):">
                    <el-input v-model="weightMsg.weightGross"  v-thousands.weightGross="weightMsg"></el-input>
                </el-form-item>
            </el-row>
            <el-row>
                <el-form-item label="皮重(调整):">
                    <el-input v-model="weightMsg.weightTare"  v-thousands.weightTare="weightMsg"></el-input>
                </el-form-item>
                <el-form-item label="净重(调整):">
                    <el-input v-model="weightMsg.netWeight"  v-thousands.netWeight="weightMsg"></el-input>
                </el-form-item>
            </el-row>
            <el-row>
                <el-form-item label="超载:">
                    <el-input v-model="weightMsg.overloadWeight"  v-thousands.overloadWeight="weightMsg"></el-input>
                </el-form-item>
                <el-form-item label="路耗:">
                    <el-input v-model="weightMsg.lossWeight"  v-thousands.lossWeight="weightMsg"></el-input>
                </el-form-item>
            </el-row>
            <el-row>
                <el-form-item label="原发数:">
                    <el-input v-model="weightMsg.originalWeight"  v-thousands.originalWeight="weightMsg"></el-input>
                </el-form-item>
                <el-form-item label="合理路耗:">
                    <el-input v-model="weightMsg.allowLossWeight"  v-thousands.allowLossWeight="weightMsg"></el-input>
                </el-form-item>
            </el-row>
          <div class="detail">
            <div align="center">
              <el-button type="primary" @click="doSubmit">提交</el-button>
                <el-button @click="detailVisible = false">取消</el-button>
            </div>
          </div>
        </el-form>
      </el-drawer>
      <!--车辆选择弹窗-->
      <TruckDialog ref="TruckDialog" @getTruckData="getTruckData">
      </TruckDialog>
      <!--司机选择弹窗-->
      <DriverDialog ref="DriverDialog" @getDriverData="getDriverData">
      </DriverDialog>
      <!--发运计划选择弹窗-->
      <TransPlanDialog ref="TransPlanDialog" @getTransPlanData="getTransPlanData">
      </TransPlanDialog>
        <!--派车单选择弹窗-->
        <TransportDialog ref="TransportDialog" @getTransportData="getTransportData">
        </TransportDialog>
    </div>
</template>

<script>
  import { addWeight } from '@/api/weightingManagent/weight.js'
  import TruckDialog from '@/components/dialog/truckDialog.vue'
  import DriverDialog from '@/components/dialog/driverDialog.vue'
  import TransPlanDialog from '@/components/dialog/transPlanDialog.vue'
  import TransportDialog from '@/components/dialog/transportDialog.vue'
    export default {
      name: 'addWeightForm',
      components: {
        TruckDialog,
        DriverDialog,
        TransPlanDialog,
        TransportDialog
      },
      data () {
        return {
          detailVisible: false,
          radioVal: 1,
          transportMsg:{
              transCode:'',
              planCode:'',
              companyName:'',
              productName:'',
              processType:'',
              truckNumber:'',
              axleName:'',
              driverName:'',
              driverPhone:'',
              truckTrailId:''
          },
          weightMsg:{
              measuredGross:'',
              grossTime:'',
              measuredTare:'',
              tareTime:'',
              netWeightMeasured:'',
              deductWeight:'',
              deductWeightImpurity:'',
              deductWeightWater:'',
              overloadAdjustWeight:'',
              weightGross:'',
              weightTare:'',
              netWeight:'',
              overloadWeight:'',
              overloadAdjustWeight:'',
              originalWeight:'',
              allowLossWeight:'',
              lossWeight:''
          },
          editForm: {
            transport: {
              id: '',
              truckTrailId:'',
              truckId: '',
              truckNumber: '',
              driverId: '',
              productId: '',
              originalDate: '',
              originalGross: '',
              originalTare: '',
              originalWeight: '',
              state: '',
              transProps: '',
              transportPlanId: ''
            },
            gross: {
              id: '',
              truckTrailId:'',
              weightMeasured: '',
              weightTime: ''
            },
            tare: {
              id: '',
              truckTrailId:'',
              weightMeasured: '',
              weightTime: ''
            },
            weight: {
                truckTrailId:'',
                weightTare:'',
                weightGross:'',
                deductWeight:'',
                overloadAdjustWeight:'',
                overloadWeight:'',
                deductWeightWater:'',
                deductWeightImpurity:'',
                netWeightMeasured:'',
                netWeight:'',
                originalWeight:'',
                originalDate:'',
                allowLossWeight:'',
                lossWeight:''
            }
          }
        }
      },
      methods: {
        init (method) {
            if(method === 'add'){
                this.detailVisible = true
                this.$nextTick(() => {
                    Object.keys(this.editForm.transport).forEach((key) => (this.editForm.transport[key] = ''))
                    Object.keys(this.transportMsg).forEach((key) => (this.transportMsg[key] = ''))
                    Object.keys(this.weightMsg).forEach((key) => (this.weightMsg[key] = ''))
                })
            }
        },
      	handleClose(done) {
			this.$Msg.confirm({
				title:'您确定要关闭吗？',
				content:this.GLOBAL.FORM_CLOSE_TIPS,
				confirmCall:()=>{
					done();
				}
			})
		},

        doSubmit () {
            this.editForm.gross.truckTrailId = this.transportMsg.truckTrailId
      	    this.editForm.gross.weightMeasured = this.weightMsg.measuredGross
            this.editForm.gross.weightTime = this.weightMsg.grossTime
            this.editForm.tare.truckTrailId = this.transportMsg.truckTrailId
            this.editForm.tare.weightMeasured = this.weightMsg.measuredTare
            this.editForm.tare.weightTime = this.weightMsg.tareTime
            this.editForm.weight.truckTrailId = this.transportMsg.truckTrailId
            this.editForm.weight.weightTare = this.weightMsg.measuredTare
            this.editForm.weight.weightGross = this.weightMsg.measuredGross
            this.editForm.weight.deductWeight = this.weightMsg.deductWeight
            this.editForm.weight.overloadAdjustWeight = this.weightMsg.overloadAdjustWeight
            this.editForm.weight.overloadWeight = this.weightMsg.overloadWeight
            this.editForm.weight.deductWeightWater = this.weightMsg.deductWeightWater
            this.editForm.weight.deductWeightImpurity = this.weightMsg.deductWeightImpurity
            this.editForm.weight.netWeightMeasured = this.weightMsg.netWeightMeasured
            this.editForm.weight.netWeight = this.weightMsg.netWeight
            this.editForm.weight.originalWeight = this.weightMsg.originalWeight
            this.editForm.weight.allowLossWeight = this.weightMsg.allowLossWeight
            this.editForm.weight.lossWeight = this.weightMsg.lossWeight
      	    console.log(this.editForm)
          addWeight(this.editForm).then(({data}) => {
            if (data.code === '200') {
              this.$message({
                message: '补录成功',
                type: 'success'
              })
              this.detailVisible = false
              this.$emit('refreshDataList')
            }
          })
        },
        // 司机选择弹窗
        getDriverClient () {
          this.$refs['DriverDialog'].dialogVisible = true
        },
        // 司机选择数据回显
        getDriverData (row) {
          this.transportMsg.driverName = row.name
          this.transportMsg.driverPhone = row.phone
          this.editForm.transport.driverId = row.id
          this.dialogVisible = false
        },
        // 发运计划选择弹窗
        getTransPlanClient () {
          this.$refs['TransPlanDialog'].dialogVisible = true
        },
        // 发运计划选择数据回显
        getTransPlanData (row) {
          console.log(1200)
          console.log(row)
          this.transportMsg.planCode = row.planCode
          this.transportMsg.companyName = row.business.companyName
          this.transportMsg.productName = row.product.name
          this.transportMsg.processType = row.business.processType
          // this.editForm.transport.transportPlanId = row.id
          // this.editForm.transport.productId = row.productId
          // this.editForm.transport.truckNumUnexecuted = row.truckNumPlanned
          // this.editForm.transport.truckNumExecuted = row.truckNumExecuted
          // this.editForm.transport.effectiveHourTransport = row.effectiveHourTransport
          // this.editForm.transport.effectiveHourLoad = row.effectiveHourLoad
          // this.editForm.transport.transPriceToDriver = row.transPriceToDriver

          if (row.business.processType === 1 || row.business.processType === 3 || row.business.processType === 4 || row.business.processType === 5) {
            this.editForm.transport.transProps = 1  // 派车属性（字典transProps）（1:装货）
          }
          if (row.business.processType === 2 || row.business.processType === 6) {
            this.editForm.transport.transProps = 2  // 派车属性（字典transProps）（2:卸货；）
          }
          this.editForm.transport.processType = row.business.processType  // 业务流程
          this.editForm.transport.transportPlanId = row.id  // 发运计划ID
          this.editForm.transport.transCompanyId = '' // 承运商Id
          this.editForm.transport.transMode = ''  // 派车模式（字典transMode）(1:普通派车；2:复合派车)
          this.editForm.transport.truckNumUnexecuted = row.truckNumPlanned // 可执行车数
          this.editForm.transport.truckNumExecuted = row.truckNumExecuted // 已执行车数
          // this.editForm.originalWeight = '' //  原发/实收数
          // this.editForm.transport.originalDate = row.sendStartDate //  原发时间（装货时间）
          this.editForm.transport.effectiveHourTransport = row.effectiveHourTransport // 进厂有效时长(时)装货-进厂
          this.editForm.transport.effectiveHourLoad = row.effectiveHourLoad  //  派车单有效时长(时)接单-装货
          this.editForm.transport.transPriceToDriver = row.transPriceToDriver //  运费单价2(给司机的运费单价)
          this.editForm.transport.sourceType = 1 //  来源类型(1:自己；2:三方物流平台A；3:...)
          this.editForm.transport.thirdPlatDataId = ''  // 第三方物流平台数据ID
          //  展示
          this.editForm.transport.planCode = row.planCode //  发运计划编号
          this.editForm.transport.companyName = row.business.companyName  // 往来名称
          this.editForm.transport.dataTypeTrans = row.dataType // 数据类别
          this.editForm.transport.productName = row.product.name // 货物名称
          this.editForm.transport.surpQuantity = row.business.surpQuantity // 业务余量
          this.dialogVisible = false
        },
        // 车辆选择弹窗
        getTruckClient () {
          this.$refs['TruckDialog'].dialogVisible = true
        },
        getTruckData (row) {
          this.transportMsg.truckNumber = row.truckNumber
          this.transportMsg.axleName = row.axle.axle
          this.editForm.transport.truckId = row.id
          this.editForm.transport.truckNumber = row.truckNumber
          this.dialogVisible = false
        },
          // 派车单选择弹窗
          getTransportClient () {
              this.$refs['TransportDialog'].init('repairRecord')
          },
          // 派车单选择数据回显
          getTransportData (row) {
      	    console.log(row)
              this.editForm.transport = row
              this.transportMsg.truckTrailId = row.truckTrailId
              this.transportMsg.processType = row.business.processType
              this.transportMsg.planCode =row.transportPlan.planCode
              this.transportMsg.companyName = row.business.companyName
              this.transportMsg.productName = row.product.name
              this.transportMsg.truckNumber = row.truckNumber
              this.transportMsg.axleName = row.axle.axle
              this.transportMsg.driverName = row.truckDriver.name
              this.transportMsg.driverPhone = row.truckDriver.phone
              this.transportMsg.transCode = row.transCode
              this.dialogVisible = false
          },
          changeRadio(){
              this.editForm.transport = {
                id: '',
                truckTrailId: '',
                truckId: '',
                truckNumber: '',
                driverId: '',
                productId: '',
                originalDate: '',
                originalGross: '',
                originalTare: '',
                originalWeight: '',
                state: '',
                transProps: '',
                transportPlanId: ''
              }
              // Object.keys(this.editForm.transport).forEach((key) => (this.editForm.transport[key] = ''))
              Object.keys(this.transportMsg).forEach((key) => (this.transportMsg[key] = ''))
              console.log(this.editForm.transport)
          }
      }
    }
</script>

<style lang="scss" scoped>
    @import "@/assets/scss/config.scss";
  .drawerForm-wrapper{
    ::v-deep.el-drawer{
        .el-drawer__body{
            padding-bottom: 24px;
            .el-input__inner{
                width: 220px !important;
            }
            .el-button.save{
                background: #F59A23;
                color: #FFFFFF;
                border: 1px solid #F59A23;
                margin-right: 5px;
                margin-left: 15px;
            }
            .el-button.save+.el-button{
                margin-right: 5px;
            }
            .el-button.save:hover{
                background-color: #e98f23 !important;
                color: #FFFFFF;
                border: 1px solid #e98f23;
            }
        }
        .mark{
            font-size: 14px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: #FF3E3E;
            margin-bottom: 30px;
            i{
                margin-right: 5px;
            }
        }
        .el-form{
            .title .el-form-item{
                color: #000000;

                .el-form-item__label{
                    color: #000000;
                }
                span{
                    font-size: 16px;
                }
            }
            .el-form-item{
                margin-right: 15px;
            }
            .el-form-item.require{
                .el-form-item__label{
                    color: #1089FF;
                }
            }
            .el-form-item.select{
                .el-input__inner{
                    cursor: pointer;
                }
            }
            .adjust-content{
                padding: 0 10px;
                background: #EEEEEE;
                height: 36px;
                border: 1px solid #AAAAAA;
                border-radius: 4px;
                color: #999999;
                cursor: not-allowed;
            }
            .adjust-content:hover{
                border-color: $--color-primary-liyu;
            }
            div.adjust-content{
                width: 220px;
            }
            p.adjust-content{
                display: inline-block;
                width: 140px;
                margin: 0 10px 0 0;
            }
            .price{
                .el-checkbox{
                    color: #1089FF;
                    .el-checkbox__inner{
                        border: 1px solid #1089FF;
                    }
                }
                .el-checkbox.is-checked{
                    .el-checkbox__inner{
                        border-color: $--color-primary-liyu;
                    }
                }
            }
        }
        .detail{
            margin-top: 10px;
        }
    }
  }
</style>
